﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Script.Services;
using KishOnlineCommone;
using KishOnlineDomain.Controller;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class UserManagement
{
    [OperationContract]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public ResultDTO AddUser(UserDTO user)
    {
        var result = new ResultDTO();
        //this function let to add just member user
        user.Roles.Clear();
        user.Roles.Add(RoleTypes.Memebr);
        var current = System.Web.HttpContext.Current.Session["User"];
        if (current != null)
        {
            user.ID = ((UserDTO)current).ID;
            var res = new UserController().UpdateUser(user);
            result.IsSucceed = res.IsSucceed;
            result.Message = res.Message;
        }
        else
            result = new UserController().RegisterUser(user);
        return result;
    }
    [OperationContract]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public UserDTO GetCurrentUser(UserDTO user)
    {
        return UserController.GetCurrentUser();
    }
}
